import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { Content } from './content.entity';

@Entity('attachments')
export class Attachment {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ name: 'file_url', length: 1024 })
  fileUrl: string;

  @Column({ name: 'file_name', length: 255 })
  fileName: string;

  @Column({ name: 'attachment_type', length: 100, nullable: true })
  attachmentType: string;

  @Column({ name: 'created_by', nullable: false })
  createdBy: string;

  @ManyToOne(() => Content, { nullable: true, createForeignKeyConstraints: false })
  @JoinColumn({ name: 'content_id' })
  content: Content;

  @Column({ name: 'content_id', nullable: true })
  contentId: string;

  @CreateDateColumn({ name: 'created_at' })
  createdAt: Date;
}
